microbit = codesters.Microbit()
microbit.show_string("hello")
data = microbit.get_light()
microbit.show_number(data)
data_list = []
time_list = []
my_display = codesters.ScatterPlot(time_list, data_list)
time = 0
def interval():
data = microbit.get_light()
data_list.append(data)
global time
time_list.append(time)
my_display.update(time_list, data_list)
time += 1
my_display.set_title("Time vs. Light")
stage.event_interval(interval, 2)
t = codesters.Teacher()
microbit_input = "get_magnet"
function_calls = t.find_function(microbit_input)
set_titles = t.find_function("set_title")
length = len(function_calls)
# Changing the first .get_temp() command is optional.
# Therefore, we need to be sure to get the correct
# .get_light() call. Some students might change both (making
# the length of lights_length 2), and some might only change
# the second command as instructed.
if length == 2:
try:
tval1 = function_calls[1][1]
tval2 = function_calls[1][0]
except:
tval1 = "DNE"
tval2 = "DNE"
elif length == 1:
try:
tval1 = function_calls[0][1]
tval2 = function_calls[0][0]
except:
tval1 = "DNE"
tval2 = "DNE"
else:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = set_titles[0][1].lower().replace(" ", "")
tval4 = t.get_indent_at_line(set_titles[0][0])
except:
tval3 = "DNE"
tval4 = "DNE"
t1 = TestObjective()
t1.add_success("data=" in tval1 and tval2 == 4, "Great job!")
t1.add_failure(tval2 == 0, "Oops! Did you remember to change the text that says .get_temp() inside your interval event?")
t1.add_failure(tval1 == "DNE", "Did you change the type of input you're getting in your interval event?")
t2 = TestObjective()
t2.add_success("timevs.magnetism" in tval3 and tval4 == 4, "Great job!")
t2.add_failure("timevs.light" in tval3, "Did you change the title of your scatter plot?")
t2.add_failure(tval3 == "DNE", "Did you delete your .set_title command?")
t2.add_failure(tval4 != 4, "Oops! Make sure you indented your .set_title() command 4 spaces inside your interval event!")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)